package com.ajs.multipledatasources.controller;

import com.ajs.multipledatasources.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.ajs.multipledatasources.entity.Teacher;
import com.ajs.multipledatasources.entity.Student;
import com.ajs.multipledatasources.service.StudentService;

/**
 * 多数据源事务测试
 * 
 * @author acer
 *
 */
@RestController
public class TransactionController {
	@Autowired
	private StudentService studentService;
	@Autowired
	private TeacherService teacherService;

	@RequestMapping("/test1")
	public String addStudent(String name,int age) {
		Student student = new Student();
		student.setName(name);
		student.setAge(age);
		studentService.addStudent(student);
		return "success";
	}

	@RequestMapping("/test2")
	public String addTeacher(String name,int age) {
		Teacher teacher = new Teacher();
		teacher.setName(name);
		teacher.setAge(age);
		teacherService.addTeacher(teacher);
		return "success";
	}

	
}
